<?php

class Admin_Form_Boletimdesempenho extends Zend_Form
{

    public function init()
    {
        Zend_Loader::loadClass('dominio','library');
        
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $id = $front->getRequest()->getParam('id', 0);
        $alu_id = $front->getRequest()->getParam('alu_id', 0);
        
        $url .= '/aluno/alu_id/'.$alu_id;
        
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        
        $this->setName('form');
        
        if($id > 0){
           $query = 'SELECT SQL_CACHE * FROM BOLETIM_DESEMPENHO WHERE BTD_ID = ' . $id;
           $data = $db->fetchRow($query);
        }
        
        
        $el = new Zend_Form_Element_Hidden('BTD_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $arr = array('0'=>'Nenhum');
        $query = 'SELECT SQL_CACHE FAC_ID,FAC_NOM FROM FACULDADE WHERE FAC_STA = 1 ORDER BY FAC_NOM ASC';
        $row = $db->fetchAll($query);
        foreach($row as $r) $arr[$r['FAC_ID']] = $r['FAC_NOM']; 
        $el = new Zend_Form_Element_Select('FAC_ID',array('onchange' => ''));
        $el->setLabel('Instituição de Ensino')
        ->setRequired(true)
        ->addMultiOptions($arr); 
        $el->setAttrib('class', 'faculdade');
        $el->setAttrib('required', '');
        $this->addElement($el); 
        
        $arr = array('0'=>'Nenhum');
        $query = 'SELECT SQL_CACHE FAP_ID,FAP_NOM FROM FACULDADE_PROVA WHERE FAC_ID = "'.$data['FAC_ID'].'" AND FAP_STA = 1 ORDER BY FAP_NOM ASC';
        $row = $db->fetchAll($query);
        foreach($row as $r) $arr[$r['FAP_ID']] = $r['FAP_NOM']; 
        $el = new Zend_Form_Element_Select('FAP_ID',array('onchange' => ''));
        $el->setLabel('Prova')
        ->addMultiOptions($arr);
        $el->setRegisterInArrayValidator(false);
        $el->setAttrib('class', 'provas');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('BTD_ANO');
        $el->setLabel('Ano')
        ->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('BTD_SEM');
        $el->setLabel('Semestre')
        ->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        
        $html = '<div class="ln disciplinas">';
        
        $query = 'SELECT SQL_CACHE b.*,d.DCP_NOM FROM BOLETIM_DESEMPENHO_DISC b, DISCIPLINA d WHERE b.BTD_ID = "'.$data['BTD_ID'].'" AND b.DCP_ID = d.DCP_ID ORDER BY b.BDD_ID';
        $row = $db->fetchAll($query);
        foreach($row as $r){  
            $html .= '<div class="cnt_el">';
            $html .= 'Disciplina: <span class="cmp_m">'.$r['DCP_NOM'].'</span> <input type="hidden" name="d[]" value="'.$r['DCP_ID'].'" >';
            $html .= ' &nbsp; Nº Questões: <input type="text" class="nummin" name="n[]" value="'.$r['BDD_NQU'].'" readonly="">';
            $html .= ' &nbsp; Peso: <input type="text" class="nummin" name="p[]" value="'.$r['BDD_PES'].'" readonly="">';
            $html .= ' &nbsp; Acertos: <input type="text" class="nummin" name="a[]" value="'.$r['BDD_ACT'].'" maxlength="3">';
            $html .= '</div>';
        }
        
        $html.= '</div>';
        
        $el = new Zend_Form_Element('html',array( 'helper'=>'formNote', 'value'=> $html ));
        $this->addElement($el);
        
        
        if($id > 0){
            $el = new Zend_Form_Element_Checkbox('BTD_STA',array('checked'=>'checked'));
            $el->setLabel('Ativo');
            $this->addElement($el);
        }
        
        $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
         
        $btn = new Zend_Form_Element_Button('Voltar',array('disableLoadDefaultDecorators' =>true));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
    }


}

